# coding=utf-8
import json

from django.db import models


class ESBChannel(models.Model):
    name = models.CharField(u"通道名称", max_length=64, help_text=u'通道名称，长度限制为64字符，例如"查询服务器列表"')
    path = models.CharField(u"通道路径", max_length=255, help_text=u'通道请求路径，例如"/host/get_host_list/"')
    comp_conf = models.TextField(u"组件配置", default="", null=True, blank=True)

    class Meta:
        db_table = "esb_channel"
        unique_together = ("path", "method")

    @property
    def comp_conf_dict(self):
        try:
            return dict(json.loads(self.comp_conf))
        except Exception:
            return {}




